
 
package Main;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class NewGame extends JFrame
{
	private boolean ready;
	private JFrame window;
	
	void setReady(boolean isIt) 
	{
		ready = isIt;
	}
	
	public NewGame(final Container c, JFrame theWin) 
	{
		window = theWin;
		//JFrame Setup
		this.setTitle("New Game");
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		Container space = this.getContentPane();
		//Ask for Name in NORTH
		final JTextField askNameField = new JTextField("New_Player", 15);
		askNameField.setEnabled(true);
		askNameField.selectAll();
		JPanel namePanel = new JPanel();
		namePanel.add(new JLabel("Your Name: "));
		namePanel.add(askNameField);
		space.add(namePanel, BorderLayout.NORTH);
		//Ship Selector in CENTER
		ShipSelector pickShip = new ShipSelector(this);
		space.add(pickShip, BorderLayout.CENTER);
		//Start Game button in SOUTH
		JButton start = new JButton("Start Game!");
		space.add(start, BorderLayout.SOUTH);
		//adding action to the Start Game button...
		start.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				if (!ready || (askNameField.getText()).length() < 1) 
				{
					//temp solution before inner windowing
					System.out.println("Select a Ship to continue...");
				}
				else 
				{
					//this '1' needs to represent the chosen ship
					Session theSession = new Session(1, askNameField.getText(),
							1, c, window);
					theSession.tellLevel();
					dispose();
				}
			}
		});
		
		this.addWindowListener(new WindowListener() 
		{
			//Make sure the level doesn't start this way..
			public void windowClosing(WindowEvent e) 
			{
				dispose();
			}
			//what the hell is all this about? --BIG interface--
			public void windowIconified(WindowEvent e) {}
			public void windowDeactivated(WindowEvent e){}
			public void windowClosed(WindowEvent e){}
			public void windowDeiconified(WindowEvent e){}
			public void windowActivated(WindowEvent e){}
			public void windowOpened(WindowEvent e){}
		});
		
		setSize(350, 220);
		setVisible(true);
		
	}
}
